do "E:\yungyu\lottery_baby\do\set_environment.do"

capture log close
log using "$log\2.5.construct_daa_for_analysis_child_quality_`c(current_date)'.log" , replace
clear
set more off

foreach x in  first { //single
	foreach y in /*2 5 10*/ 5 /*30 50*/ {
		use "$wdata\project_lottery_child_quality_full_panel_93109.dta", clear

		merge m:1 win_year real_win_year pers_idn spouse_idn using "$wdata\single_and_first_event_winners.dta"
		drop if _m == 2
		drop _m
		
		keep if `x'_event_`y'k == 1
		//keep if inrange(norm_year,-3,6) //from 3 years before to 6 year after lottery
		drop *event*k
		
		** Delete observation die before observation period
		//drop if pers_death_year < win_year + 7

		keep if win_year != 102
		merge m:1 houseid year using "$wdata\project_lottery_fertility_b3a6_`x'_`y'k.dta"
		keep if _m == 3
		drop _m
		
		** Prize Variable
		replace prize10M = winyr_pers_real_prize_aftertax / 10000 //prize in 10 Million
		replace prize5M = prize10M * 2
		
		** Interaction Terms
		replace currentxprize = 0
		replace currentxprize = prize5M if current == 1
		
		save "$wdata\project_lottery_child_quality_b3a6_`x'_`y'k.dta", replace
	}
}

log close
